<?php
namespace Home\Controller;

use Utuo\DistributionShopForeground;

class DisShopArticleController extends DistributionShopForeground {
    
    /**
     * 初始化
     */
    public function _init() {
        layout('disshop');
        $this->setModelName('DistributionShop');
        $this->setModelControllerName('DisShop');
        if ( !in_array(ACTION_NAME, array('qrImage')) ) { // 排除不支持分享跳转的链接
            $this->setSupportRedirect(isset($_REQUEST['debug'])?false:true);
        }
    }
    
    
    public function showAction() {
        $id = I('id', 0, "intval");
        $article = M("DistributionShopArticle")->where(array(
            'cid' => $this->cid,
            'id' => $id,
        ))->find();
        M("DistributionShopArticle")->where(array(
            'cid' => $this->cid,
            'id' => $id,
        ))->setInc("views");
        $this->assign('item', $article);
        $this->assign('qrurl', U('DisShopArticle/qrImage', array('sid'=>$this->cid)));
        $this->display ( "{$this->modelControllerName}/articleShow" );
    }
    
    public function qrImageAction() {
        $util = \Api\Utils\QrcodeUtil::getInstance(array(
            'cid' => $this->cid,
            'openId' => $this->user['openId'],
            'modelName' => 'DistributionShop',
        ));
        $code = $util->getQrCode();
        list($type, $ext) = explode('/', $code['mime']);
        header("Content-Type:image/{$ext}");
        echo $code['image'];
    }
    
}